package trading.algo;

import java.util.TimerTask;

import trading.bo.DBAccessorBO;
import trading.bo.IBAccessorBO;

/**
 * This task updates Current_Account_Status db table, Current_Stock_Positions db table
 * and Current_Option_Positions db table
 * 
 * @author ntantai
 *
 */
public class UpdateAccountValueTask extends TimerTask {
	private IBAccessorBO ibAccessorBO;
	private DBAccessorBO dbAccessorBO;
	private boolean shouldCleanTable;
	
	public UpdateAccountValueTask(IBAccessorBO ibAccessorBO, DBAccessorBO dbAccessorBO, boolean shouldCleanTable) {
		this.ibAccessorBO = ibAccessorBO;
		this.dbAccessorBO = dbAccessorBO;
		this.shouldCleanTable = shouldCleanTable;
	}

	@Override
	public void run() {
	    if (shouldCleanTable) {
		    dbAccessorBO.cleanUpCurrentStockPositions();
		    dbAccessorBO.cleanUpCurrentOptionPositions();
		    dbAccessorBO.cleanUpAccountStatus();
	    }
		ibAccessorBO.reqAccountUpdates();
	}

	public static int secondsNeeded() {
	    return 2;
	}
}
